<!-- <template>
	<view class="choosePosition">
		<view class="choosePositionBox" @click="goto()" v-if="address == ''">
			<image class="imageStyle" src="../../static/image/repair-position/position.png"></image>
			<view class="tip">请选择报修地点</view>
			<image class="imageStyle imageStyle-right" src="../../static/image/repair-position/enter-arrow.png"></image>
		</view>

		<view class="choosePositionBox" @click="goto()" v-else>
			<view class="content">
				<view class="firstLine">
					<image class="imageStyle" src="../../static/image/repair-position/position.png"></image>
					<view class="mainTitle title">{{ name }}</view>
				</view>
				<view class="subTitle title">{{ address }}</view>
			</view>
			<image class="imageStyle imageStyle-right" src="../../static/image/repair-position/enter-arrow.png"></image>
		</view>
	</view>

	<view class="chooseMessage"></view>
</template>

<script>
	// 根据环境引入小程序插件或模拟数据
	let chooseLocation;

	// 判断环境，如果是小程序环境，则引入插件，否则使用模拟数据
	if (process.env.VUE_APP_PLATFORM === 'mp-weixin') {
		chooseLocation = requirePlugin('chooseLocation');
	} else {
		// 模拟数据
		chooseLocation = {
			getLocation: () => ({
				name: 'Uniapp模拟位置名称',
				address: 'Uniapp模拟地址',
				// 其他模拟数据
			}),
			setLocation: () => {},
		};
	}

	export default {
		data() {
			return {
				// 经度
				latitude: 0,
				// 纬度
				longitude: 0,
				address: '',
				name: '',
				// fullAddress:'',
			};
		},
		created() {
			// 获取当前的位置信息
			uni.getLocation({
				type: 'wgs84',
				success: (res) => {
					console.log(res);
					this.latitude = res.latitude;
					this.longitude = res.longitude;
				},
			});
		},
		methods: {
			goto() {
				console.log("输出",this.latitude);
				console.log(this.longitude);
				const key = 'RJYBZ-V6ZKJ-IPKF5-DCMGQ-CMGSO-NTFMY'; // 使用在腾讯位置服务申请的key
				const referer = 'test'; // 调用插件的app的名称
				const location = JSON.stringify({
					latitude: this.latitude,
					longitude: this.longitude,
				});
				const category = '基础设施';

				wx.navigateTo({
					url: 'plugin://chooseLocation/index?key=' +
						key +
						'&referer=' +
						referer +
						'&location=' +
						location +
						'&category=' +
						category,
				});
			},
		},
		// 从地图选点插件返回后，在页面的onShow生命周期函数中能够调用插件接口，取得选点结果对象
		onShow() {
			const location = chooseLocation.getLocation(); // 如果点击确认选点按钮，则返回选点结果对象，否则返回null
			console.log("输出location：",location);
			if (location && location.address && location.name) {
				this.address = location.address;
				this.name = location.name;
				// this.fullAddress = this.address + '---' + this.name
			}
		},
		onUnload() {
			// 页面卸载时设置插件选点数据为null，防止再次进入页面，geLocation返回的是上次选点结果
			chooseLocation.setLocation(null);
		},
	};
</script>

<style lang="scss">
	page {
		background-color: #333333;
	}

	.choosePositionBox {
		display: flex;
		width: 96vw;
		height: 140rpx;
		margin: 30rpx auto;
		align-items: center;
		border-radius: 30rpx;
		border-left: 2px solid #ffb612;
		border-right: 2px solid #ffb612;
		background-color: #4f4f4f;
		box-sizing: border-box;

		.tip {
			color: white;
		}

		// 图标icon统一样式
		.imageStyle {
			width: 70rpx;
			height: 70rpx;
		}

		.imageStyle-right {
			position: absolute;
			right: 30rpx;
		}

		// 标题省略
		.title {
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp: 1;
			overflow: hidden;
			color: white;
		}

		.mainTitle {
			font-size: 45rpx;
		}

		.subTitle {
			font-size: 30rpx;
			margin-left: 9vw;
		}

		.firstLine {
			height: 60rpx;
			display: flex;
		}

		.content {
			width: 75vw;
		}
	}
</style> -->